package org.idea.qiyu.framework.jmh.demo;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;

/**
 * @Author linhao
 * @Date created in 10:53 下午 2021/12/16
 */
public class TestStringAppendDemo {



    public static void testStringBufferAdd() {
        long begin = System.currentTimeMillis();
        StringBuffer item = new StringBuffer();
        for (int i = 0; i < 100000; i++) {
            item = item.append("-");
        }
        long end = System.currentTimeMillis();
        System.out.println("StringBuffer 耗时：" + (end - begin) + "ms");
    }


    public static void testStringBuilderAdd() {
        long begin = System.currentTimeMillis();
        StringBuilder item = new StringBuilder();
        for (int i = 0; i < 100000; i++) {
            item = item.append("-");
        }
        long end = System.currentTimeMillis();
        System.out.println("StringBuilder 耗时：" + (end - begin) + "ms");
    }


    public static void testStringAdd() {
        long begin = System.currentTimeMillis();
        String item = new String();
        for (int i = 0; i < 100000; i++) {
            item = item + "-";
        }
        long end = System.currentTimeMillis();
        System.out.println("String 耗时：" + (end - begin) + "ms");
    }

    public static void main(String[] args) {
        for(int i=0;i<20;i++){
            testStringAdd();
        }
    }
}
